package com.dy.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * <p>
 * 菜单表
 * </p>
 *
 * @author dy
 * @since 2022-03-02
 */
@Data
@TableName("tb_menu")
@ApiModel(value = "Menu对象", description = "菜单表")
public class Menu implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("菜单/按钮ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty("上级菜单ID")
    private Long parentId;

    @ApiModelProperty("菜单/按钮名称")
    private String menuName;

    @ApiModelProperty("菜单URL")
    private String url;

    @ApiModelProperty("权限标识")
    private String perms;

    @ApiModelProperty("图标")
    private String icon;

    @ApiModelProperty("类型 0菜单 1按钮")
    private String type;

    @ApiModelProperty("排序")
    private Long orderNum;

    @ApiModelProperty("创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty("修改时间")
    private LocalDateTime modifiedTime;

    @ApiModelProperty("0：不可用，1：可用")
    private Integer available;

    @ApiModelProperty("0:不展开，1：展开")
    private Integer open;

    @ApiModelProperty("子菜单")
    @TableField(exist = false)
    private List<Menu> childMenus;

    /**
     * 功能描述: <br>
     * 〈排序，根据order〉
     *
     * @Param:
     * @Return:
     * @Author: dy
     * @Date: 2022/3/3 19:07
     */
    public static Comparator<Menu> order() {
        Comparator<Menu> comparator = (o1, o2) -> {
            if (o1.getOrderNum() != o2.getOrderNum()) {
                return (int) (o1.getOrderNum() - o2.getOrderNum());
            }
            return 0;
        };
        return comparator;
    }

}
